package cn.lyjuan.android.demofive.ui.component.time_picker_dialog;

import android.app.Dialog;
import android.app.DialogFragment;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.widget.TimePicker;

import java.util.Calendar;

/**
 * Created by chad on 2016/1/20.
 */
public class TimePickerDialogFragment extends DialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        Calendar cal = Calendar.getInstance();
        int hour = cal.get(Calendar.HOUR);
        int minute = cal.get(Calendar.MINUTE);

        TimePickerDialog dialog = new TimePickerDialog(this.getActivity(), timeSetListener, hour, minute, true);

        return dialog;
    }

    private TimePickerDialog.OnTimeSetListener timeSetListener = new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            ((OnTimeSetCallback) TimePickerDialogFragment.this.getActivity()).onTimeSet(view, hourOfDay, minute);
        }
    };

    public interface OnTimeSetCallback
    {
        void onTimeSet(TimePicker view, int hourOfDay, int minute);
    }
}
